package rdfareaderget;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import usefulstuffs.Encoder;

import com.ibm.icu.impl.Utility;

public class RDFaReaderGET {
	private static final String JAVA_RDFA_EXTRACTOR_URL = "http://rdf-in-html.appspot.com/translate/";
	
	public static InputStream extractRDFaUsingGET(String url, String format) throws Exception{
		if(format == null || (format.equalsIgnoreCase("html")
				& !format.equalsIgnoreCase("xhtml"))){
			format = "HTML";
		}
		StringBuilder sb = new StringBuilder();
		sb.append(JAVA_RDFA_EXTRACTOR_URL);
		sb.append("?uri=").append(Encoder.encode(url));
		sb.append("&parser=").append(format.toUpperCase());
		
		URL requestURL = new URL(sb.toString());
		HttpURLConnection connection = (HttpURLConnection) requestURL.openConnection();
		connection.setRequestMethod("GET");
		
		return connection.getInputStream();
	}
}
